package site.shihuan.helpdesk.im.manager;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import site.shihuan.helpdesk.common.util.IdWorker;
import site.shihuan.helpdesk.im.dao.SvcHiMsgDao;
import site.shihuan.helpdesk.im.message.impl.ChatMessage;
import site.shihuan.helpdesk.im.model.Constants;
import site.shihuan.helpdesk.im.model.po.SvcHiMsgPO;

import java.util.Collections;
import java.util.List;

/**
 * TODO
 *
 * @author 周世焕
 * @Date 2021/2/23 16:10
 */
@Slf4j
@Component
public class MessageManager {

    private static final int msgLimit = 20;

    @Autowired
    private SvcHiMsgDao svcHiMsgDao;

    /**
     * 存储聊天消息
     * @param chatMessage
     */
    public void createMessage(ChatMessage chatMessage){
        SvcHiMsgPO svcHiMsgPO = new SvcHiMsgPO();
        svcHiMsgPO.setMsgId(IdWorker.nextId());
        svcHiMsgPO.setSender(chatMessage.getSender());
        svcHiMsgPO.setReceiver(chatMessage.getReceiver());
        svcHiMsgPO.setMsg(chatMessage.getMsg());
        svcHiMsgPO.setDate(System.currentTimeMillis());
        svcHiMsgPO.setType(chatMessage.getType());
        svcHiMsgPO.setTenantId(chatMessage.getTenantId());
        svcHiMsgPO.setSeen(Constants.MESSAGE_SEEN);
        svcHiMsgPO.setContactId(chatMessage.getContactId());
        svcHiMsgDao.insertSelective(svcHiMsgPO);
    }
}
